package com.cl.master.controller;

import com.cl.master.common.Result;
import com.cl.master.domain.Note;
import com.cl.master.service.NoteService;
import com.cl.master.service.impl.NoteServiceImpl;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author xc
 * @Date 2023/5/9 22:29
 * @Version 1.0
 */
@RestController//=@Controller+@ResponseBody表示该类是springboot的一个controller，且返回的数据为JSON格式
// @Component
@RequestMapping("sewage")
public class NoteController {

    @Resource
    NoteServiceImpl noteService;

    //删除数据
    @PostMapping("deleteNote")
    public Result deleteNote(Note note) {
        noteService.deleteNote(note.getTitle());
        Result result = Result.success("删除成功");
        return  result;

    }

    //保存数据
    @PostMapping("saveNote")
    public Result saveNote(Note note) {
        noteService.saveNote(note);
        Result result = Result.success("成功保存");
        return  result;
    }

    //查询数据
    @RequestMapping("getNote")
    public Result getNote(){
        List<Map<String,Object>> data = noteService.getNote();
        Result result = Result.success(data);
        return result;
    }
}
